//
//  RootViewController.m
//  XYMaterial
//
//  Created by 肖扬 on 15/12/9.
//  Copyright © 2015年 肖扬. All rights reserved.
//

#import "RootViewController.h"
#import "LoginViewController.h"
#import "RegisteredViewController.h"
@interface RootViewController ()

@end

@implementation RootViewController
@synthesize loginBtn,registeredBtn;
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self initView];
    // Do any additional setup after loading the view.
}
-(void)initView{
    UIImageView *bgImg = [self createImageViewFrame:CGRectMake(0, 0, SWIDTH, SHEIGHT) image:nil imageName:@"图层-4" tag:0];
    [self.view addSubview:bgImg];
    
    UIImageView *smallImg = [self createImageViewFrame:CGRectMake(105, 100, SWIDTH - 210, SWIDTH - 210) image:nil imageName:@"启动" tag:0];
    smallImg.backgroundColor = [UIColor clearColor];
    [self.view addSubview:smallImg];
    
    UILabel *titleLab = [self createLabelFrame:CGRectMake(0, 115+SWIDTH - 210, SWIDTH, 25) title:@"更受欢迎的板材交易中心" titleColor:[UIColor whiteColor] tag:0];
    titleLab.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:titleLab];
    
    UIButton *tempBtn1 = [self createButtonFrame:CGRectMake(20, SHEIGHT - 135 , SWIDTH - 40, 43) title:@"注册有材网" viewController:self selector:@selector(registeredClick:) tag:10];
    [tempBtn1 setBackgroundImage:[UIImage imageNamed:@"注册登录默认按钮"] forState:UIControlStateNormal];
    
    [self.view addSubview:tempBtn1];
    
    UIButton *tempBtn2 = [self createButtonFrame:CGRectMake(20, SHEIGHT - 78, SWIDTH - 40, 43) title:@"登录有材网" viewController:self selector:@selector(loginClick:) tag:10];
    
//    [tempBtn2 setBackgroundImage:[UIImage imageNamed:@"注册登录默认按钮"] forState:UIControlStateNormal];
    [tempBtn2 setBackgroundColor:[UIColor whiteColor]];
    Radio(tempBtn2, whiteColor);
    [self.view addSubview:tempBtn2];
    
}
-(void)registeredClick:(UIButton *)sender{
    //TODO:注册
    RegisteredViewController *registerVC = [[RegisteredViewController alloc]init];
    [self.navigationController pushViewController:registerVC animated:YES];
}
-(void)loginClick:(UIButton *)sender{
    //TODO:登录
    LoginViewController *loginVC = [[LoginViewController alloc]init];
    [self.navigationController pushViewController:loginVC animated:YES];
}
//创建UILabel  tag值为三位数
- (UILabel *)createLabelFrame:(CGRect)frame
                        title:(NSString *)title
                   titleColor:(UIColor *)color
                          tag:(NSInteger)tag{
    UILabel *tempLabel = [[UILabel alloc]initWithFrame:frame];
    [tempLabel setBackgroundColor:[UIColor clearColor]];
    [tempLabel setText:title];
    [tempLabel setTag:tag];
    [tempLabel setTextColor:color];
    return tempLabel;
}
//创建UIButton tag值为四位数
- (UIButton *)createButtonFrame:(CGRect)frame
                          title:(NSString *)title
                 viewController:(id)viewController
                       selector:(SEL)selector
                            tag:(NSInteger)tag{
    UIButton *tempButton = [UIButton buttonWithType:0];
    [tempButton setFrame:frame];
    [tempButton setTag:tag];
    [tempButton setBackgroundColor:[UIColor clearColor]];
    [tempButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [tempButton setTitle:title forState:UIControlStateNormal];
    [tempButton addTarget:viewController action:selector forControlEvents:UIControlEventTouchUpInside];
    return tempButton;
}
//创建UIImageView tag值为五位数
- (UIImageView *)createImageViewFrame:(CGRect)frame
                                image:(UIImage *)image
                            imageName:(NSString *)imageName
                                  tag:(NSInteger)tag{
    UIImageView *tempImageView = [[UIImageView alloc]initWithFrame:frame];
    [tempImageView setBackgroundColor:[UIColor clearColor]];
    if (image) {
        tempImageView.image = image;
    }else{
        tempImageView.image = [UIImage imageNamed:imageName];
    }
    [tempImageView setTag:tag];
    return tempImageView;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
